package com.fyzk.activity.prize;

import com.alibaba.fastjson.JSON;
import com.fyzk.bean.JLPrizeInfo;
import com.fyzk.bean.JLPrizeResponse;
import com.fyzk.net.Commands;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import http.Common.CommandUtil;
import http.StringResultBean;

public class JLPrizeActivity extends JC_PrizeBaseActivity {
    private JCLQ_PrizeAdapter adapter;
    protected List<JLPrizeInfo> list_infor = new ArrayList<JLPrizeInfo>();

    @Override
    protected void init() {
        super.init();
        adapter = new JCLQ_PrizeAdapter(JLPrizeActivity.this, list_infor);
        listView.setAdapter(adapter);
    }

    @Override
    protected String getTopTitle() {
        return "竞彩篮球开奖";
    }

    @Override
    public void jc_requestData() {
        super.jc_requestData();
        findJLPrizeResult();
    }

    private void findJLPrizeResult() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("officialDate", currDate);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        httpPostJson(CommandUtil.FINDJCLQRESULTS, Commands.FINDJCLQRESULTS, jsonObject, true);
    }

    @Override
    protected void onSuccess(int requestCode, StringResultBean resultBean, String result) {
        super.onSuccess(requestCode, resultBean, result);
        netProgressView.dismiss();
        JLPrizeResponse response = JSON.parseObject(resultBean.getData(), JLPrizeResponse.class);
        list_infor.clear();
        list_infor.addAll(response.getRaces());
        adapter.notifyDataSetChanged();
        int session = response.getRaces().size();
        time.setText(currDate + " " + weekTime + " " + " 共" + session + "场");
    }

    @Override
    protected void onFailure(int requestCode, String errorCode, String message) {
        if(errorCode.equals("20004")){
            time.setText(currDate + " " + weekTime + " 共0场");
            netProgressView.noneRecord(message);
        }else{
            netProgressView.fail(message);
        }
    }
}
